/*
 * @lc app=leetcode.cn id=409 lang=typescript
 *
 * [409] 最长回文串
 */

// @lc code=start

function longestPalindrome(s: string): number {
    const cache = new Map<string, number>();
    s.split("").forEach((i) => {
        cache.set(i, (cache.get(i) || 0) + 1);
    });
    let hasOdd = false;
    let result = 0;
    for (const iterator of cache.values()) {
        if (iterator % 2) {
            hasOdd = true;
            result = result + iterator - 1;
        } else {
            result += iterator;
        }
    }
    return hasOdd ? result + 1 : result;
}

// @lc code=end
